<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>解构</title>
</head>

<body>
  <script>
    /*  let a = 1
     let b = 2
     let c = 3 */

    //let a = 1, b = 2, c = 3


    //数组解构
    //let [a, b, c] = [1, 2, 3]

    //解构设置默认值,如果解构对应值,则赋值,否则使用默认值代替
    let [a, b = 0, c] = [1, , 3]
    console.log(a, b, c)


    //对象解构
    const user = {
      username: 'admin',
      gender: '男',
      age: 20
    }
    /*  let username = user.username
     let gender = user.gender
     let age = user.age */

    //默认情况下,解构的变量名必须和对象的属性名保持一致
    //let { username, gender, age } = user

    //也可以对解构变量进行重命名
    let { username: name, gender: sex, age } = user
    console.log(name, sex, age)

    //字符串解构
    const [n1, n2, n3] = 'css'
    console.log(n1, n2, n3)
  </script>
</body>

</html>